package com.raysdata.smartcity.web.sys;

import com.raysdata.smartcity.HelperClazz;
import com.raysdata.smartcity.dao.sys.MenuDao;
import com.raysdata.smartcity.dto.Menu;
import com.raysdata.smartcity.dto.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by yl on 2016/10/17.
 */
@Controller
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    public MenuDao menuDao;

    @RequestMapping("/getMenu")
    public void getMenu(HttpServletRequest request, HttpServletResponse response) {
        // 获取当前用户
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("LoginUser");
        List<Menu> menuList = menuDao.queryMenus(user.getUser_id());

        HelperClazz.renderJson(response, HelperClazz.toJSON4Page(menuList));
    }
}
